﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace TextEditorDP
{
    public class InsertRTFCommand: Command
    {
        CRichTextBox editor;
        string text;
        Font font;
        RtfColor textColor;
        RtfColor backColor;
        string history;
        public InsertRTFCommand(ref CRichTextBox editor, string text, Font font, RtfColor textColor, RtfColor backColor)
        {
            this.editor = editor;
            this.text = text;
            this.font = font;
            this.textColor = textColor;
            this.backColor = backColor;
        }

        #region Command Members

        public bool Execute()
        {
            history = editor.Rtf;
            // Insert text with a little formatting
            editor.InsertTextAsRtf(text, font, textColor, backColor);
            return true;
        }

        public void UnExecute()
        {
            editor.Rtf = history;
        }

        public bool CanUndo()
        {
            return true;
        }

        #endregion
    }
}
